<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Admin
 * Date: 19.06.11
 * Time: 16:59
 * To change this template use File | Settings | File Templates.
 */
    $xml = simplexml_load_file('h:\parse\res\Platonanet.xml');
  /* todo: сделать проверку на правильность разметки файла */
    $handle = fopen('h:\parse\res\query.sql','w');
foreach($xml->channel->item as $item){
    $title = str_replace("'","&#039;", (string)$item->title);
    $description = str_replace("'","&#039;",(string)$item->description);
    $category = str_replace("'","&#039;",(string)$item->category);
    $date = str_replace("'","&#039;",(string)$item->date);
    $author = str_replace("'","&#039;",(string)$item->author);
    $alt_name = str_replace("'","&#039;",(string)$item->alt_name);
    preg_match('@<!\[CDATA\[([^\]]*)\]\]@', $item->short_story->asXML(), $matches);
    $short_story = str_replace("'","&#039;",$matches[1]);
    preg_match('@<!\[CDATA\[([^\]]*)\]\]@', $item->full_story->asXML(), $matches);
    $full_story = str_replace("'","&#039;",$matches[1]);
    $metatitle = str_replace("'","&#039;",(string)$item->metatitle);
    $sql = "INSERT INTO `thinker`.`dle_post` (`id`, `autor`, `date`, `short_story`, `full_story`, `title`, `descr`, `category`, `alt_name`, `tags`, `metatitle`) VALUES (NULL, '{$author}', '{$date}', '{$short_story}', '{$full_story}', '{$title}', '{$description}', '{$category}', '{$alt_name}','{$tags}', '{$metatitle}');\n";
    fwrite($handle, $sql);
  }
   fclose($handle);
  echo 'Done!';
?>
 
